from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `attr` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `create_time` DATETIME(6) NOT NULL  COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL  COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(32) NOT NULL UNIQUE COMMENT '属性名称',
    `val` VARCHAR(255)   COMMENT '属性值',
    `_type` VARCHAR(32)   COMMENT '属性类型'
) CHARACTER SET utf8mb4 COMMENT='商品属性表';
        CREATE TABLE IF NOT EXISTS `category` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `create_time` DATETIME(6) NOT NULL  COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL  COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(32) NOT NULL UNIQUE COMMENT '分类名称',
    `level` INT NOT NULL  DEFAULT 1,
    `pid_id` INT COMMENT '父级分类',
    CONSTRAINT `fk_category_category_5214d862` FOREIGN KEY (`pid_id`) REFERENCES `category` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='商品分类表';
        CREATE TABLE IF NOT EXISTS `good` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `create_time` DATETIME(6) NOT NULL  COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL  COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(512) NOT NULL UNIQUE COMMENT '商品名称',
    `price` DOUBLE   COMMENT '商品价格',
    `number` INT   COMMENT '商品数量',
    `introduce` LONGTEXT   COMMENT '商品介绍',
    `big_log` VARCHAR(512)   COMMENT '商品大图',
    `small_log` VARCHAR(512)   COMMENT '商品小图',
    `state` INT NOT NULL  COMMENT '商品状态，0未通过 1审核中 2已审核' DEFAULT 0,
    `is_promote` INT NOT NULL  COMMENT '是否畅销，0否 1是' DEFAULT 0,
    `hot_number` INT   COMMENT '热卖数量',
    `weight` INT   COMMENT '商品重量'
) CHARACTER SET utf8mb4 COMMENT='商品表';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS `attr`;
        DROP TABLE IF EXISTS `category`;
        DROP TABLE IF EXISTS `good`;"""
